package com.kkmp4.controller;

import com.kkmp4.model.User;
import com.kkmp4.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by zhangsen on 2016/11/3.
 */
@Controller
@RequestMapping("/")
public class SimpleController {

    @Autowired
    private UserRepository userRepository;

    @RequestMapping("t1")
    @ResponseBody
    public String test1()
    {
        User user=new User();
        user.setName("zhangsen");
        return String.valueOf(userRepository.save(user));
    }

    @RequestMapping("t3")
    @ResponseBody
    public String test3()
    {
        return userRepository.findUserByName("zhangsen").toString();
    }

    @RequestMapping("/t2")
    public String test2()
    {
        return "index";
    }
}
